package com.msh.platform.elm.service.impl;

import com.msh.platform.elm.common.util.DateUtils;
import com.msh.platform.elm.dao.SaleInfoRepository;
import com.msh.platform.elm.dao.SaleSpecRepository;
import com.msh.platform.elm.entity.SaleInfo;
import com.msh.platform.elm.entity.SaleSpec;
import com.msh.platform.elm.service.SaleInfoService;
import com.msh.platform.elm.vo.SaleInfoVO;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SaleInfoServiceImpl implements SaleInfoService{

    @Autowired
    private SaleInfoRepository saleInfoRepository;
    @Autowired
    private SaleSpecRepository saleSpecRepository;
    
    public List<SaleInfoVO> getDqSale(int pubNoId, String dqStr){
		int weekValue = DateUtils.getIntWeekByDate(dqStr);  //星期几的数字
		int dayValue = DateUtils.getDayByDate(dqStr);  //几号的数字
		List<SaleInfo> saleInfoList = saleInfoRepository.findDqSale(pubNoId, weekValue, dayValue, dqStr);
		List<SaleInfoVO> saleInfoVOList = new ArrayList<SaleInfoVO>();
		for(SaleInfo saleInfo : saleInfoList) {
			SaleSpec spec = saleSpecRepository.getOne(saleInfo.getSpecId());
			SaleInfoVO saleInfoVO = new SaleInfoVO();
			BeanUtils.copyProperties(saleInfo, saleInfoVO);
			saleInfoVO.setSpecName(spec.getName());
			saleInfoVOList.add(saleInfoVO);
		}
		return saleInfoVOList;
    }

}
